import { Block } from '@design/core/model';
const TYPE = {
  NODE: 'application/x-node-type'
};

function encode(node) {
  return JSON.stringify(node.toJS());
}

function setDataTransfer(dataTransfer, node) {
  const data = encode(node);
  dataTransfer.setData(TYPE.NODE, data);
}

function getNode(dataTransfer) {
  const data = dataTransfer.getData(TYPE.NODE);
  if (data) {
    const obj = JSON.parse(data);
    return Block.fromJSON(obj);
  }
}

export { getNode, setDataTransfer };
